import request from "@/api";
import type {IApiResponse, IApiResponseList} from "@/types";
import type {IUserQueryParams, IUserModel, IUserResponse} from "@/types/system/user.ts";


/**
 * 用户列表
 * @param params 查询参数
 */
export const getUserListApi = (params: IUserQueryParams): Promise<IApiResponseList<IUserResponse>> => {
    return request({
        method: "GET",
        url: "/system/user/",
        params,
    })
}


/**
 * 添加用户
 * @param formData 用户表单
 */
export const createUserApi = (formData: IUserModel): Promise<IApiResponse<IUserResponse>> => {
    return request({
        method: "POST",
        url: "/system/user/",
        data: formData,
    })
}


/**
 * 更改用户
 * @param record 用户数据
 */
export const updateUserApi = (record: IUserResponse): Promise<IApiResponse<IUserResponse>> => {
    return request({
        method: "PUT",
        url: `/system/user/${record.id}/`,
        data: record,
    })
}


/**
 * 删除用户
 * @param record 用户数据
 */
export const removeUserApi = (record: IUserResponse): Promise<IApiResponse<{}>> => {
    return request({
        method: "DELETE",
        url: `/system/user/${record.id}/`,
    })
}
